<?php
namespace app\api\controller;

use app\api\model\ActivityModel;
use think\Controller;

class Activity extends  Controller
{
    function atvdetail() {
        $activityid = input('get.activityid');
        $model = new ActivityModel();
        $result = $model->atvdetail($activityid);
        if ($result) {
            return json_encode($result);
        }else {
            return  json_encode(['id'=>0]);
        }

    }
    function atvlist() {
        $model = new ActivityModel();
        $result = $model->atvlist();
        return json_encode($result);
    }
    function activityenroll() {
        $sessionid = input('get.sessionid');
        $userid = input('get.userid');
        $activityid = input('get.activityid');

        session_start();
        $redis = getRedis();
        if ($sessionid!='' && $sessionid == $redis->get($userid)) {
            $model = new ActivityModel();
            $result = $model->activityenroll($userid,$activityid);
            return json_encode($result);
        }
        return  json_encode(['error'=>'sessionid无效']);
    }
}